home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / System / Sample JGNE⁄cdev 1.2.1 / (MyJGNE.π) / MyInitialize.c < prev    next >
Encoding:
Text File  |  1994-09-08  |  3.5 KB  |  96 lines  |  [TEXT/KAHL]

  1. //
  2. // MyInitialize.c
  3. //
  4. // Written by Ken Worley, 06/03/94, using Symantec Think C 7.0
  5. // Copyright 1994.
  6. // AOL KNEworley
  7. // internet KNEworley@aol.com
  8. //
  9. //    Feel free to use this code in a project of your own, but give me proper
  10. //    credit in your documentation or about box.  Feel free to distribute this
  11. //    code in its entirety to anyone, but never do so without the copyright
  12. //    notice above nor without its accompanying files.  This code is NOT in
  13. //    the public domain.  Use of this code in a commercial product requires my
  14. //    permission.
  15. //
  16. // This file takes care of allocating memory, loading resources, and initializing
  17. // variables specific to the function of the filter.  We use this file mainly to
  18. // set function specific code off from the rest of the code that doesn't change
  19. // much from project to project.
  20. //
  21. // This routine is allowed to change the values of installTask, and showIcon.
  22. // These variables have already been initialized by the calling routine, but their
  23. // values can be changed here if need be.  installTask determines whether or
  24. // not the filter code is actually installed, and showIcon determines whether or
  25. // not the icon is shown at startup time.  (showIcon is called showStartupIcon
  26. // in the calling routine)
  27. //
  28. //    We use what I call a 'preferences' resource to save some settings between
  29. //    restarts.  For the most part, this same information is also held in memory
  30. //    (in the shared data structure) while the computer is running so that the
  31. //    task code and cdev can access the settings.  The resource is normally accessed
  32. //    once here, then accessed and possibly changed later by the
  33. //    control panel code.
  34. //
  35. //    This preferences resource contains values that indicate whether or not the
  36. //    task should be installed (control panel on or off) and whether or not the
  37. //    icon should be shown at startup time.
  38. //
  39.  
  40. Boolean MyInitialize( myDataPtr myData, Boolean *installTask, Boolean *showIcon )
  41. {
  42.     Boolean                stillOK = true;    /* return value */
  43.     CPprefsHandle        prefsHandle;    /* Handle to the cdev prefs rsrc */
  44.  
  45.     // Initialize the preferences resource handle in myData to NULL
  46.     
  47.         myData->CPprefsRsrc = NULL;
  48.             
  49.     //    Load the control panel's preferences resource to see if we should show
  50.     //    the icon at startup and the task should be 'on.'  After we've read it,
  51.     //    release it.  The control panel will reload it.  If we cannot read the
  52.     //    resource from the file (probably because it doesn't yet exist), just
  53.     //    assume true for on/off and show icon and use the default modifier keys.
  54.     //  The control panel will create a new preferences resource if need be.
  55.  
  56.          myData->CPon = true;    /* preset to 'on' unless we find otherwise */
  57.                              /* installTask was also preset to true above */
  58.          
  59.          /* This sample captures mouse clicks when these modifiers are down */
  60.          
  61.          myData->CPmodifiers = controlKey + optionKey + shiftKey;
  62.                                          /* preset modifiers to default */
  63.          
  64.          prefsHandle = NULL;
  65.          
  66.          prefsHandle = (CPprefsHandle)Get1Resource( kCPprefsRsrcType,
  67.                                                          kCPprefsRsrcID );
  68.          if ( prefsHandle )
  69.          {
  70.              if ( !(*prefsHandle)->On )    // control panel set to off?
  71.              {
  72.                  *installTask = false;
  73.                  myData->CPon = false;
  74.              }
  75.              
  76.              if ( !(*prefsHandle)->ShowIcon )    // show icon?
  77.                  *showIcon = false;
  78.              
  79.              myData->CPmodifiers = (*prefsHandle)->modifiers;
  80.                  
  81.              ReleaseResource( (Handle)prefsHandle );
  82.          }
  83.  
  84.     /* If any keys are down, do not load (this means ANY key) */
  85.     
  86.         {
  87.             KeyMap    theKeys;
  88.             
  89.             GetKeys( theKeys );
  90.             if ( theKeys[0] || theKeys[1] || theKeys[2] || theKeys[3] )
  91.                 stillOK = false;
  92.         }
  93.     
  94.      return stillOK;
  95. }
  96.